package com.ruoyi.project.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.product.domain.ProductsShare;
import com.ruoyi.project.product.service.ProductsShareService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 产品分享Controller
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/system/share")
public class ProductsShareController extends BaseController
{
    @Autowired
    private ProductsShareService productsShareService;


    /**
     * 查询产品分享列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProductsShare zProductsShare)
    {
        startPage();
        List<ProductsShare> list = productsShareService.selectProductsShareList(zProductsShare);
        return getDataTable(list);
    }

    /**
     * 导出产品分享列表
     */
    @Log(title = "产品分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductsShare zProductsShare)
    {
        List<ProductsShare> list = productsShareService.selectProductsShareList(zProductsShare);
        ExcelUtil<ProductsShare> util = new ExcelUtil<ProductsShare>(ProductsShare.class);
        util.exportExcel(response, list, "产品分享数据");
    }

    /**
     * 分享链接生成
     * @param productsShare
     * @return
     */
    @PostMapping
    public AjaxResult addProductsShare(@RequestBody ProductsShare productsShare)
    {

        return AjaxResult.success(productsShareService.addProductsShare(productsShare));
    }

    /**
     * 获取分享的文件详情
     */
    @Anonymous
    @GetMapping("/getProductsShare")
    public AjaxResult getProductsShare( String shareOnlyId)
    {
        return AjaxResult.success(productsShareService.selectProductsShareByShareId(shareOnlyId));
    }

    /**
     * 获取分享的文件详情
     */
    @Anonymous
    @GetMapping("/getFileDetail")
    public AjaxResult getFileDetail( Long shareId,Long productId )
    {
        return AjaxResult.success(productsShareService.getFileDetail(shareId,productId));
    }


}
